package com.cs.widgetrv.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.cs.base.router.RouterActivityPath;
import com.cs.widgetrv.R;
import com.cs.widgetrv.activity.multi.ChooseMultipleItemUseTypeActivityRV;
import com.cs.widgetrv.activity.node.ChooseNodeUseTypeActivityRV;
import com.cs.widgetrv.adapter.HomeAdapter;
import com.cs.widgetrv.base.RVBaseActivity;
import com.cs.widgetrv.entity.HomeEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: HomeActivityRV
 * @Date: 2021/12/14
 * @Author: CS
 * @Description:
 */
@Route(path = RouterActivityPath.RV.HOME_RV)
public class HomeActivityRV extends RVBaseActivity {

    private RecyclerView mRecyclerView;
    private HomeAdapter adapter;
    List<HomeEntity> data = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        setTitle("HomeActivityRV");
        setBackBtn();
        mRecyclerView = findViewById(R.id.recycler_view);
        initAdapter();
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                HomeEntity homeEntity = data.get(position);
                if(homeEntity.cls!=null){
                    Intent intent = new Intent(HomeActivityRV.this,homeEntity.cls);
                    startActivity(intent);
                }
            }
        });

    }

    private void initAdapter() {
        data.add(new HomeEntity("Animation", AnimationUseActivity.class, R.mipmap.gv_animation));
        data.add(new HomeEntity("Header/Footer", HeaderAndFooterUseActivityRV.class, R.mipmap.gv_header_and_footer));
        data.add(new HomeEntity("EmptyView", EmptyViewUseActivityRV.class, R.mipmap.gv_empty));
        data.add(new HomeEntity("ItemClick", ItemClickActivityRV.class, R.mipmap.gv_item_click));
        data.add(new HomeEntity("DataBinding", DataBindingUseActivityRV.class, R.mipmap.gv_databinding));
        data.add(new HomeEntity("DiffUtil", DiffUtilActivityRV.class, R.mipmap.gv_databinding));
        data.add(new HomeEntity("MultipleItem", ChooseMultipleItemUseTypeActivityRV.class, R.mipmap.gv_multipleltem));
        data.add(new HomeEntity("Quick Section", SectionQuickUseActivityRV.class, R.mipmap.gv_section));
        data.add(new HomeEntity("Node", ChooseNodeUseTypeActivityRV.class, R.mipmap.gv_expandable));
        data.add(new HomeEntity("LoadMore", LoadMoreRefreshUseActivityRV.class, R.mipmap.gv_pulltorefresh));
        data.add(new HomeEntity("DragAndSwipe", DragAndSwipeUseActivityRV.class, R.mipmap.gv_drag_and_swipe));
        data.add(new HomeEntity("UpFetch", UpFetchUseActivityRV.class, R.drawable.gv_up_fetch));

        adapter = new HomeAdapter(data);
        adapter.setAnimationEnable(true);
        mRecyclerView.setAdapter(adapter);
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

}
